﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Smart.MembershipService;
using System.Web.Security;
using Smart.UI.BaseClasses;

namespace Smart.Account
{
    public partial class Login : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            bool isValid = Global.MembershipService.ValidateUser(tbEmail.Text, tbPassword.Text);
            lblErrorMessage.Visible = !isValid;

            if (isValid)
            {
                User loggedUser = Global.MembershipService.GetUserByEmail(tbEmail.Text);
                string displayName = String.Format("{0} {1}", loggedUser.FirstName, loggedUser.LastName);

                Login(loggedUser.UserId, displayName, Request.QueryString["returnUrl"]); 
            }
            else
            {
                upErrorMessage.Update();
            }
        }
    }
}